﻿using System;
using System.Runtime.Serialization;
using System.ServiceModel;

namespace RRSimulator.BlobManager.Service.Requests
{
    [MessageContract]
    [KnownType(typeof(UploadFileStreamRequest))]
    [KnownType(typeof(UploadBlockStreamRequest))]
    public class BlobManagerMessageRequestBase : IBlobManagerRequest, IDisposable
    {
        private bool _isDisposed;

        [MessageHeader(MustUnderstand = true)]
        public string BlobName { get; set; }

        [MessageHeader(MustUnderstand = true)]
        public string ContainerName { get; set; }

        ~BlobManagerMessageRequestBase()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool isDisposing)
        {
            if (!_isDisposed)
            {
                if (isDisposing)
                {
                    BlobName = null;
                    ContainerName = null;
                }

                _isDisposed = true;
            }
        }
    }
}
